﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveToCenter : MonoBehaviour {

	public GameLogic logic;

	// Use this for initialization
	void Start () {
		
	}
	
	public float speed = 30;
	// Update is called once per frame
	void Update () 
	{
		if(!logic.gameLose)
		{
			var dir = -Vector3.Normalize(transform.localPosition);

			transform.Translate(speed * dir * Time.deltaTime);
		}
	}

	/*void OnCollisionEnter(Collision collision)
	{
		Destroy(gameObject);
		Destroy(collision.gameObject);
	}*/

	void OnTriggerEnter(Collider collider)
	{
		if(collider.name != "Center")
		{
			Destroy(gameObject);
			Destroy(collider.gameObject);

			int soundIndex = 4;
			//int soundIndex = Random.Range(1, 4);
			SoundManager.Instance.PlaySoundWithID(soundIndex);
		}
		else
		{
			logic.gameLose = true;
			SoundManager.Instance.PlaySoundWithID(6);
			SoundManager.Instance.StopBGM();
		}
	}
}
